<%@ Page Language="C#" 
    ValidateRequest="false" 
    MasterPageFile="~/Template.master" 
    AutoEventWireup="true" 
    CodeFile="AddEditProduct.aspx.cs" 
    Inherits="XZ.Web.UI.Admin.AddEditProduct" 
    Title="XZ WebShop - Add/Edit Product" %>
<%@ Register Src="../Controls/FileUploader.ascx" TagName="FileUploader" TagPrefix="xz" %>
<%@ Register Src="../Controls/RatingDisplay.ascx" TagName="RatingDisplay" TagPrefix="xz" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>

<asp:Content ID="MainContent" ContentPlaceHolderID="MainContent" Runat="Server">
   <div class="sectiontitle">
      <asp:Literal runat="server" ID="lblNewProduct" Text="Insert New Product" />
      <asp:Literal runat="server" ID="lblEditProduct" Text="Edit Product" Visible="false" />
   </div>
   <p></p>
    <asp:DetailsView ID="dvwProduct" runat="server" 
        AutoGenerateDeleteButton="True" 
        AutoGenerateEditButton="True"
        AutoGenerateInsertButton="True" 
        AutoGenerateRows="False" 
        DataKeyNames="Id" 
        DataSourceID="objCurrProduct"
        DefaultMode="Insert" 
        HeaderText="Product Details" 
        OnItemCreated="dvwProduct_ItemCreated" 
        OnDataBound="dvwProduct_DataBound" 
        OnModeChanged="dvwProduct_ModeChanged">
      <FieldHeaderStyle Width="108px" />
      <Fields>
         <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
            SortExpression="ID" />
         <asp:BoundField DataField="AddedDate" HeaderText="Added Date" InsertVisible="False"
            ReadOnly="True" SortExpression="AddedDate" HtmlEncode="false" DataFormatString="{0:f}" />
         <asp:BoundField DataField="AddedBy" HeaderText="Added By" InsertVisible="False" ReadOnly="True"
            SortExpression="AddedBy" />         
         <asp:BoundField DataField="Votes" HeaderText="Votes" InsertVisible="False" ReadOnly="True"
            SortExpression="Votes" />
         <asp:BoundField DataField="AverageRating" HeaderText="Rating" InsertVisible="False"
            HtmlEncode="false" DataFormatString="{0:N2}" ReadOnly="True" SortExpression="AverageRating" />
         <asp:TemplateField HeaderText="Category" SortExpression="CategoryId">
            <ItemTemplate>
               <asp:Label ID="lblCategory" runat="server" Text='<%# Eval("CategoryTitle") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:DropDownList ID="ddlCategories" runat="server" DataSourceID="objAllCategories"
                  DataTextField="Title" DataValueField="Id" SelectedValue='<%# Bind("CategoryId") %>' Width="100%" />
               <asp:ObjectDataSource ID="objAllCategories" runat="server" SelectMethod="GetCategories"
                  TypeName="XZ.Logistics.WebShop.Category"></asp:ObjectDataSource> 
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Title" SortExpression="Title">
            <ItemTemplate>
               <asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtTitle" runat="server" Text='<%# Bind("Title") %>' Width="100%" MaxLength="256"></asp:TextBox>
               <asp:RequiredFieldValidator ID="valRequireTitle" runat="server" ControlToValidate="txtTitle" SetFocusOnError="true"
                  Text="The Title field is required." ToolTip="The Title field is required." Display="Dynamic"></asp:RequiredFieldValidator>
            </EditItemTemplate>
         </asp:TemplateField>         
         <asp:TemplateField HeaderText="Description" SortExpression="Description">
            <ItemTemplate>
               <asp:Label ID="lblDescription" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <FCKeditorv2:FCKeditor id="txtDescription" runat="server" Value='<%# Bind("Description") %>'
                  ToolbarSet="TheBeerHouse" Height="400px" Width="100%" />
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="SKU" SortExpression="SKU">
            <ItemTemplate>
               <asp:Label ID="lblSKU" runat="server" Text='<%# Eval("SKU") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtSKU" runat="server" Text='<%# Bind("SKU") %>' Width="100%" MaxLength="256"></asp:TextBox>
               <asp:RequiredFieldValidator ID="valRequireSKU" runat="server" ControlToValidate="txtSKU" SetFocusOnError="true"
                  Text="The SKU field is required." ToolTip="The SKU field is required." Display="Dynamic"></asp:RequiredFieldValidator>
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Unit Price" SortExpression="UnitPrice">
            <ItemTemplate>
               <asp:Label ID="lblUnitPrice" runat="server" Text='<%# Eval("UnitPrice", "{0:N2}") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtUnitPrice" runat="server" Text='<%# Bind("UnitPrice", "{0:N2}") %>' Width="100%" MaxLength="256"></asp:TextBox>
               <asp:RequiredFieldValidator ID="valRequireUnitPrice" runat="server" ControlToValidate="txtUnitPrice" SetFocusOnError="true"
                  Text="The Unit Price field is required." ToolTip="The Unit Price field is required." Display="Dynamic"></asp:RequiredFieldValidator>
               <asp:CompareValidator ID="valUnitPriceType" runat="server" Operator="DataTypeCheck" Type="Currency"
                  ControlToValidate="txtUnitPrice" Text="The Unit Price must be a double."
                  ToolTip="The Unit Price must be a double." Display="dynamic" />
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Discount %" SortExpression="DiscountPercentage">
            <ItemTemplate>
               <asp:Label ID="lblDiscountPercentage" runat="server" Text='<%# Eval("DiscountPercentage") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtDiscountPercentage" runat="server" Text='<%# Bind("DiscountPercentage") %>' Width="100%" MaxLength="256"></asp:TextBox>
               <asp:RequiredFieldValidator ID="valRequireDiscountPercentage" runat="server" ControlToValidate="txtDiscountPercentage" SetFocusOnError="true"
                  Text="The Discount Percentage field is required." ToolTip="The Discount Percentage field is required." Display="Dynamic"></asp:RequiredFieldValidator>
               <asp:CompareValidator ID="valDiscountPercentageType" runat="server" Operator="DataTypeCheck" Type="Integer"
                  ControlToValidate="txtDiscountPercentage" Text="The Discount Percentage must be an integer."
                  ToolTip="The Discount Percentage must be an integer." Display="dynamic" />
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Units in Stock" SortExpression="UnitsInStock">
            <ItemTemplate>
               <asp:Label ID="lblUnitsInStock" runat="server" Text='<%# Eval("UnitsInStock") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtUnitsInStock" runat="server" Text='<%# Bind("UnitsInStock") %>' Width="100%" MaxLength="256"></asp:TextBox>
               <asp:RequiredFieldValidator ID="valRequireUnitsInStock" runat="server" ControlToValidate="txtUnitsInStock" SetFocusOnError="true"
                  Text="The Discount Units In Stock field is required." ToolTip="The Units In Stock field is required." Display="Dynamic"></asp:RequiredFieldValidator>
               <asp:CompareValidator ID="valUnitsInStockType" runat="server" Operator="DataTypeCheck" Type="Integer"
                  ControlToValidate="txtUnitsInStock" Text="The Units In Stock must be an integer."
                  ToolTip="The Units In Stock must be an integer." Display="dynamic" />
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Small Image Url" SortExpression="SmallImageUrl">
            <ItemTemplate>
               <asp:Label ID="lblSmallImageUrl" runat="server" Text='<%# Eval("SmallImageUrl") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtSmallImageUrl" runat="server" Text='<%# Bind("SmallImageUrl") %>' Width="100%" MaxLength="256"></asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Full Image Url" SortExpression="FullImageUrl">
            <ItemTemplate>
               <asp:Label ID="lblFullImageUrl" runat="server" Text='<%# Eval("FullImageUrl") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtFullImageUrl" runat="server" Text='<%# Bind("FullImageUrl") %>' Width="100%" MaxLength="256"></asp:TextBox>
            </EditItemTemplate>
         </asp:TemplateField>
      </Fields>
   </asp:DetailsView>
   <asp:ObjectDataSource ID="objCurrProduct" runat="server" DeleteMethod="DeleteProduct"
      InsertMethod="InsertProduct" 
      SelectMethod="GetProductById" 
      TypeName="XZ.Logistics.WebShop.Product"
      UpdateMethod="UpdateProduct">
      <DeleteParameters>
         <asp:Parameter Name="id" Type="Object" />
      </DeleteParameters>
      <UpdateParameters>
         <asp:Parameter Name="id" Type="Object" />
         <asp:Parameter Name="categoryId" Type="Object" />
         <asp:Parameter Name="title" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="description" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="sku" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="unitPrice" Type="Decimal" />
         <asp:Parameter Name="discountPercentage" Type="Int32" />
         <asp:Parameter Name="unitsInStock" Type="Int32" />
         <asp:Parameter Name="smallImageUrl" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="fullImageUrl" Type="String" ConvertEmptyStringToNull="false" />
      </UpdateParameters>
      <SelectParameters>
         <asp:QueryStringParameter Name="productId" QueryStringField="Id" Type="Object" />
      </SelectParameters>
      <InsertParameters>
         <asp:Parameter Name="categoryId" Type="Object" />
         <asp:Parameter Name="title" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="description" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="sku" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="unitPrice" Type="Decimal" />
         <asp:Parameter Name="discountPercentage" Type="Int32" />
         <asp:Parameter Name="unitsInStock" Type="Int32" />
         <asp:Parameter Name="smallImageUrl" Type="String" ConvertEmptyStringToNull="false" />
         <asp:Parameter Name="fullImageUrl" Type="String" ConvertEmptyStringToNull="false" />
      </InsertParameters>
   </asp:ObjectDataSource>   
   <p></p>
   <xz:FileUploader id="FileUploader1" runat="server" />
</asp:Content>

